[//
    async function( kuo,Context,context){
        Context.headers["content-type"] = 'application/json;charset=UTF-8';
        let $DATA = Object.assign({},this.$DATA);
        let $features = await Kuoplus(kuo.class);
        let $THIS =  this;
        let $_GET = kuo.get;
        let $LANG = this.LANG();
        let $appid  = $features['configure']['支付宝网页'] && $features['configure']['支付宝网页']['0']?$features['configure']['支付宝网页']['0']:"";
        let $keycc  = $features['configure']['支付宝网页'] && $features['configure']['支付宝网页']['2']?$features['configure']['支付宝网页']['2']:"";
        let UID = 0;
        let $state  = $_GET['state']?$_GET['state']:"";
        let $CODE   = $_GET['auth_code']?$_GET['auth_code']:"";
        let $Security = await Mem.Get('opentoken/'+$state);
        if($Security){
            kuo.sessionid = $Security.sessionid;
            Mem.Del('opentoken/'+$state)
            let $CAN = {
                'app_id':$appid,
                'method': 'alipay.system.oauth.token',
                'charset':'utf-8',
                'sign_type':'RSA2',
                'timestamp':Mode("Tools").Date("Y-m-d H:i:s"),
                'version':'1.0',
                '_input_charset':'utf-8',
                'grant_type':'authorization_code',
                'code':$CODE
            };
            $CAN['sign']=  SHA256_sign( getarray(azpaixu($CAN)),$keycc );
            let $fan = await POST("https://openapi.alipay.com/gateway.do?_input_charset=utf-8",$CAN);
            $fan = JSON.parse($fan);
            if(isset( $fan['error_response'])){
                $DATA.code = -1;
                $DATA.data =$fan['error_response']['code']
                $DATA.msg = $fan['error_response']['sub_msg']
                Context.body = JSON.stringify($DATA);
                return ;
            }
            $fan = $fan['alipay_system_oauth_token_response'];
            let $user_id = $fan['user_id']?$fan['user_id']:"";
            let $access_token = $fan['access_token']?$fan['access_token']:"";
            let $db =  await db('login_alipay');
            let $user = await $db.Where( {'userid': $user_id} ).Find();
            if( $user ){
                let $USER =  await Uid($user['uid']);
                if($USER['accountoff'] != 1){
                    $DATA.code = -1;  $DATA.msg = $LANG.accountoff;Context.body = JSON.stringify($DATA);
                    return ;
                   
                }
                $Security['uid'] = $user['uid'];
                await Mem.Put("session/"+kuo.sessionid,$Security,Expiredseconds);
                await  Kuolog('userlog',$user['uid'],0, [] ,kuo.func_,kuo.class,kuo.ip);
                if($Security.platform == "ISAPP"){
                    $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
                    $DATA.code = 1;
                    $DATA.msg = $LANG.login_true;
                    $DATA.data = $USER;
                    $DATA.apptoken = kuo.sessionid;
                    Context.body = JSON.stringify($DATA);
                }else{
                    let url = $Security.tiaozhuan?$Security.tiaozhuan:WZHOST;
                    Context.statusCode = 302;
                    Context.headers["Location"] = url ;
                    Context.body = "";
                }
                return ;
            }

            if($Security.uid && $Security.uid  > 0){
                //绑定用户
                UID = $Security.uid;
                let $chaxun = await $db.Where( {'uid': UID} ).Find();
                if($chaxun){
                    $DATA.code = -1;  $DATA.msg = $LANG.account_false;Context.body = JSON.stringify($DATA);
                    return ;
                }
            }else{

                $CAN = {
                    'app_id':$appid,
                    'method': 'alipay.user.info.share',
                    'charset':'utf-8',
                    'sign_type':'RSA2',
                    'timestamp':Mode("Tools").Date("Y-m-d H:i:s"),
                    'version':'1.0',
                    '_input_charset':'utf-8',
                    'grant_type':'authorization_code',
                    'code':$CODE,
                    'auth_token':$access_token,
                    'biz_content':"{}"
                
                };
                $CAN['sign']=  SHA256_sign( getarray(azpaixu($CAN)),$keycc );
                $fan = await POST("https://openapi.alipay.com/gateway.do?_input_charset=utf-8",$CAN);
                

                $fan = JSON.parse($fan);
                let $fan_ = {
                    'nickname' : $user_id,
                    'sex' :-1,
                    'headimgurl':''
                }; 
                if(!$fan['error_response']){
                    let $fanuser = $fan['alipay_user_info_share_response'];
                    $fan_ = {
                        'nickname' : $fanuser['nick_name']?$fanuser['nick_name']:$user_id,
                        'sex' :isset($fanuser['gender']) && $fanuser['gender'] == 'F'?'0':1,
                        'headimgurl':$fanuser['avatar']?$fanuser['avatar']:""
                    }; 
                }
                UID = await $THIS.REG({
                    "name":$fan_.nickname,
                    "sex":$fan_.sex,
                    "tou": $fan_.headimgurl,
                    "ip":kuo.ip,
                    'tuid':$Security.tuid?$Security.tuid:0
                });
               

            }
            if(!UID || UID < 1){
                $DATA.code = -1;
                $DATA.msg = $LANG.uuid_error;
                Context.body = JSON.stringify($DATA);
                return ;
            }

            $user = {
                'userid':$user_id,
                'uid': UID
            };
            $fan = $db.Insert($user);
            if($fan){
                
                $Security['uid'] = $user['uid'];
                await Mem.Put("session/"+$kuo.sessionid,$Security,Expiredseconds);
                await  Kuolog('userlog',$user['uid'],0, [],kuo.func_,kuo.class,kuo.ip);
                
                if($Security.platform == "ISAPP"){
                    $USER = await Uid( $user['uid'] );
                    $USER['avatar'] = pichttp($USER['avatar']==""?"Tpl/login/avatar/"+($USER['id']%10)+".png":$USER['avatar']);
                    $DATA.code = 1;
                    $DATA.msg = $LANG.reg_true;
                    $DATA.data = $USER;
                    $DATA.apptoken = kuo.sessionid;
                    Context.body = JSON.stringify($DATA);

                }else{
                    let url = $Security.tiaozhuan?$Security.tiaozhuan:WZHOST;
                    Context.statusCode = 302;
                    Context.headers["Location"] = url ;
                    Context.body = "";
                }

            }else{

                $DATA.code = -1;
                $DATA.msg = $LANG.reg_false;
                if($Security.platform == "ISAPP"){
                    Context.body = JSON.stringify($DATA);
                }else{
                    let url = $Security.tiaozhuan?$Security.tiaozhuan:WZHOST;
                    Context.statusCode = 302;
                    Context.headers["Location"] = url ;
                    Context.body = "";
                }
            }

        }else{
            $DATA.code = -1;
            $DATA.msg = $LANG.login_false;
            Context.body = JSON.stringify($DATA);
        }
    } 
]